package service;

import java.util.List;

import dao.ProductDao;
import pojo.PageBean;
import pojo.Product;

public class ProductService {
	ProductDao pdao;
	public List<Product> show(int currentPage,int pageSize){
		pdao = new ProductDao();
		List<Product> list=pdao.PageData(currentPage, pageSize);
		return list;
	}
//	public PageBean<Product> show(int currentPage,int pageSize) {
//		pdao = new ProductDao();
//		PageBean<Product> pb = new PageBean<Product>();
//		pb.setList(pdao.PageData(currentPage,pageSize));
//		pb.setTotal(pdao.getTotal());
//		int totalPage=(pdao.getTotal()%pageSize==0)?(pdao.getTotal()/pageSize):(pdao.getTotal()/pageSize+1);
//		pb.setTotalPage(totalPage);
//		pb.setCurrentPage(currentPage);
//		pb.setPageSize(pageSize);
//		return pb;
//	}
	public List<Product> showProductByType(int currentPage,int pageSize,String type){
		pdao = new ProductDao();
		List<Product> list=pdao.showProductByType(currentPage, pageSize, type);
		return list;
	}
	public int del(String p_id) {
		pdao = new ProductDao();
		int flag=pdao.del(p_id);
		return flag;
	
	}
	public int update(Product p) {
		pdao = new ProductDao();
		int flag=pdao.update(p);
		return flag;
	}
	public Product getProduct(String p_id) {
		pdao=new ProductDao();
		Product p = pdao.getOneProduct(p_id);
		return p;
	}
	public int add(Product p) {
		pdao =new ProductDao();
		int flag = pdao.add(p);
		return flag;
	}
	public int updatepquantity(String pid,int pquantity) {
		pdao=new ProductDao();
		int flag=pdao.updatePquantity(pid, pquantity);
		return flag;
	}

}